import requests
import unittest

# 定义一个工具类，用于发送请求
class APIClient:
    def __init__(self, base_url):
        self.base_url = base_url

    def get(self, endpoint, **kwargs):
        response = requests.get(self.base_url + endpoint, **kwargs)
        return response

    def post(self, endpoint, **kwargs):
        response = requests.post(self.base_url + endpoint, **kwargs)
        return response

    def put(self, endpoint, **kwargs):
        response = requests.put(self.base_url + endpoint, **kwargs)
        return response

    def delete(self, endpoint, **kwargs):
        response = requests.delete(self.base_url + endpoint, **kwargs)
        return response


# 定义测试用例基类
class APITestCase(unittest.TestCase):
    def setUp(self):
        self.client = APIClient('http://your-api-base-url.com')

    def test_status_code(self, response, expected_status):
        self.assertEqual(response.status_code, expected_status)

    def test_content_type(self, response, expected_content_type):
        self.assertEqual(response.headers['Content-Type'], expected_content_type)

    def test_json(self, response, expected_json):
        self.assertEqual(response.json(), expected_json)


# 定义具体的测试用例
class TestAPIEndpoints(APITestCase):
    def test_get_endpoint(self):
        response = self.client.get('/some-get-endpoint')
        self.test_status_code(response, 200)
        self.test_content_type(response, 'application/json')

    def test_post_endpoint(self):
        data = {'key': 'value'}
        response = self.client.post('/some-post-endpoint', json=data)
        self.test_status_code(response, 201)
        self.test_content_type(response, 'application/json')

    # 更多测试用例...


if __name__ == '__main__':
    unittest.main()